package com.scu.phototabuser.data;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.test.espresso.core.deps.guava.base.Objects;
import android.support.test.espresso.core.deps.guava.base.Strings;

import java.util.UUID;

/**
 * 抽象任务
 * 任务id，任务描述
 * @T t 详细任务
 *@Author tianff[tianff.scu@gmail.com]
 *@Date 2017/4/10
 *@return
 */
public class Task <T extends Taskable> {

    @NonNull
    private final String mId;

    @Nullable
    private final String mTitle;

    @Nullable
    private final String mDescription;

    private final boolean mCompleted;

    private T t;


    public Task(@Nullable String title, @Nullable String description,T t) {
        this(title, description, UUID.randomUUID().toString(), false);
        this.t=t;
    }

    public T getTaskable() {
        return t;
    }


    private Task(@Nullable String title, @Nullable String description,
                 @NonNull String id, boolean completed) {
        mId = id;
        mTitle = title;
        mDescription = description;
        mCompleted = completed;
    }

    @NonNull
    public String getId() {
        return mId;
    }

    @Nullable
    public String getTitle() {
        return mTitle;
    }


    @Nullable
    public String getDescription() {
        return mDescription;
    }

    public boolean isCompleted() {
        return mCompleted;
    }

    public boolean isActive() {
        return !mCompleted;
    }

    public boolean isEmpty() {
        return Strings.isNullOrEmpty(mTitle) &&
                Strings.isNullOrEmpty(mDescription);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Task task = (Task) o;
        return Objects.equal(mId, task.mId) &&
                Objects.equal(mTitle, task.mTitle) &&
                Objects.equal(mDescription, task.mDescription);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(mId, mTitle, mDescription);
    }

    @Override
    public String toString() {
        return "Task with title " + mTitle +" and Description: "+mDescription;
    }



}
